package com.dst.smart.dao.impl.factory;

import java.util.ArrayList;
import java.util.List;

import com.dst.smart.app.MyApplication;
import com.dst.smart.model.Room;
import com.dst.smart.model.Room;

public class RoomFactory {
	public static List<Room> list = new ArrayList<Room>();

	static {
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase().getRoom();
		}
	}

	public static List<Room> getAll() {
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase().getRoom();
		}
		return list;
	}

	public static List<Room> getLimit(int limit) {

		List<Room> resultList = new ArrayList<Room>();
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase().getRoom();
		}

		if (limit < list.size()) {
			resultList = list.subList(0, limit);
		} else {
			resultList.addAll(list);
		}
		return resultList;
	}

//	public static List<Room> getRoom(int homePageDisplays) {
//		List<Room> resultList = new ArrayList<Room>();
//		if (list.size() == 0) {
//			list = MyApplication.getInstance().getWidgetDataBase().getRoom();
//		}
//
//		for (Room arce : list) {
//			if (arce.getHomePageDisplays() == homePageDisplays) {
//				resultList.add(arce);
//			}
//		}
//		return resultList;
//	}

	public static List<String> getRoomName() {
		List<String> resultList = new ArrayList<String>();
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase().getRoom();
		}

		for (Room arce : list) {
			resultList.add(arce.getRoomName());

		}
		return resultList;
	}


	public static String getRoomName(int arceID) {
		String result="首页";
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase().getRoom();
		}

		for (Room room : list) {
			if (room.getId()==arceID) {
				result=room.getRoomName();
				break;
			}
		}
		return result;
	}

	public static void clearList() {
		list = MyApplication.getInstance().getWidgetDataBase().getRoom();
	}

	public static Room getRoom(String roomName) {
		Room room = new Room();
		room.setId(0);
		room.setRoomName("首页");

		List<Room> list = getAll();
		for (Room arc : list) {
			if (arc.getRoomName().equals(roomName)) {
				room.setId(arc.getId());
				room.setRoomName(arc.getRoomName());
				break;
			}
		}
		return room;
	}
}
